package com.bitin.adorn.modules.system.api;

import com.bitin.adorn.modules.user.domain.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.Explode;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.enums.ParameterStyle;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "user", description = "the user API")
public interface UserApi {

    @Operation(summary = "Create user", description = "This can only be done by the logged in user.", tags = {"user"})
    @ApiResponses(value = {
        @ApiResponse(
            description = "successful operation",
            content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = User.class)),
                @Content(mediaType = "application/xml", schema = @Schema(implementation = User.class))
            })
    })
    @PostMapping(value = "/user", consumes = {"application/json", "application/xml", "application/x-www-form-urlencoded"})
    default ResponseEntity<Void> createUser(@Parameter(description = "Created user object") @Valid @RequestBody User user) {
        return null;
    }

    @Operation(summary = "Delete user", description = "This can only be done by the logged in user.", tags = {"user"})
    @ApiResponses(value = {
        @ApiResponse(responseCode = "400", description = "Invalid username supplied"),
        @ApiResponse(responseCode = "404", description = "User not found")
    })
    @DeleteMapping(value = "/user/{username}")
    default ResponseEntity<Void> deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") String username) {
        return null;
    }

    @Operation(summary = "Get user by user name", tags = {"user"})
    @ApiResponses(value = {
        @ApiResponse(responseCode = "200", description = "successful operation", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = User.class)), @Content(mediaType = "application/xml", schema = @Schema(implementation = User.class))}),
        @ApiResponse(responseCode = "400", description = "Invalid username supplied", content = @Content),
        @ApiResponse(responseCode = "404", description = "User not found", content = @Content)
    })
    @GetMapping(value = "/user/{username}")
    default ResponseEntity<User> getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing. ", required = true) @PathVariable("username") String username) {
        return null;
    }

    @Operation(summary = "Logs user into the system", tags = {"user"})
    @ApiResponses(value = {
        @ApiResponse(
            responseCode = "200",
            headers = {
                @Header(name = "X-Rate-Limit", description = "calls per hour allowed by the user", schema = @Schema(type = "integer", format = "int32")),
                @Header(name = "X-Expires-After", description = "date in UTC when toekn expires", schema = @Schema(type = "string", format = "date-time"))
            },
            description = "successful operation",
            content = @Content(schema = @Schema(implementation = String.class))
        ),
        @ApiResponse(responseCode = "400", description = "Invalid username/password supplied", content = @Content)
    })
    @GetMapping(value = "/user/login", produces = {"application/xml", "application/json"})
    default ResponseEntity<String> loginUser(
        @NotNull @Parameter(description = "The user name for login", required = false) @Valid @RequestParam(value = "username", required = false) String username,
        @NotNull @Parameter(description = "The password for login in clear text", required = false) @Valid @RequestParam(value = "password", required = false) String password
    ) {
        return null;
    }

    @Operation(summary = "Logs out current logged in user session", tags = {"user"})
    @ApiResponses(
        value = {
            @ApiResponse(description = "successful operation")
        }
    )
    @GetMapping(value = "/user/logout")
    default ResponseEntity<Void> logoutUser() {
        return null;
    }

    @Operation(summary = "Update user", description = "This can only be done by the logged in user.", tags = {"user"})
    @ApiResponses(
        value = @ApiResponse(description = "successful operation")
    )
    @PutMapping(value = "/user/{username}", consumes = {"application/json", "application/xml", "application/x-www-form-urlencoded"})
    default ResponseEntity<Void> updateUser(
        @Parameter(description = "name that need to be deleted", required = true, explode = Explode.FALSE, in = ParameterIn.PATH, name = "username", style = ParameterStyle.SIMPLE, schema = @Schema(type = "string")) @PathVariable("username") String username,
        @Parameter(description = "Update an existent user in the store") @Valid @RequestBody User user
    ) {
        return null;
    }
}
